package com.dykj.fireFighting.web.base.app;


import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 企业Controller
 * @Author JacksonTu
 * @Date 2018/12/17 11:14
 */
@Slf4j
@Api(value = "app企业接口", tags = {"app企业接口"})
@RestController
@RequestMapping("/app/enterprise")
public class AppEnterpriseController {

    @DubboReference
    private IEnterpriseService enterpriseService;


    /**
     * 根据维保单位获取社会单位
     *
     * @param enterpriseId
     * @return
     */
    @ApiOperation(value = "根据维保单位获取社会单位", notes = "根据维保单位获取社会单位")
    @GetMapping("/queryUnitListByMaintenance")
    public CommonResult<List<Enterprise>> queryUnitListByMaintenance(String enterpriseId) {
        if (StringUtils.isBlank(enterpriseId)) {
            enterpriseId = ShiroUtil.getUser().getEnterpriseId().toString();
        }
        List<Enterprise> enterpriseList = enterpriseService.queryUnitListByMaintenance(enterpriseId);
        return CommonResult.success(enterpriseList);
    }

    /**
     * 根据社会单位获取维保单位
     *
     * @param enterpriseId
     * @return
     */
    @ApiOperation(value = "根据社会单位获取维保单位", notes = "根据社会单位获取维保单位")
    @GetMapping("/queryMaintenanceListByUnit")
    public CommonResult<List<Enterprise>> queryMaintenanceListByUnit(String enterpriseId) {
        Map<String, Object> params = new HashMap<>();
        if (StringUtils.isBlank(enterpriseId)) {
            enterpriseId = ShiroUtil.getUser().getEnterpriseId().toString();
            params.put("enterpriseId", enterpriseId);
        }
        List<Enterprise> enterpriseList = enterpriseService.queryMaintenanceListByUnit(params);
        return CommonResult.success(enterpriseList);
    }
}
